
(define (parse-input-object input-object)
  (define command-string (cdr (assq 'command input-object)))
  (cond
   ((string=? command-string "UP") 'up)
   ((string=? command-string "DOWN") 'down)
   ((string=? command-string "LEFT") 'left)
   ((string=? command-string "RIGHT") 'right)
   ((string=? command-string "A") 'a)
   ((string=? command-string "B") 'b)
   ((string=? command-string "X") 'x)
   ((string=? command-string "Y") 'y)
   (else
    (error "parse-input-object" "Value not recognized for command" command-string))))

(define global-game-state #f)

(define (current-level)
  (global-level global-game-state))

(define (current-menu)
  (global-menu global-game-state))

(define (api-push-input! input-object)
  (push-button! (parse-input-object input-object)))

(define (push-button! button)
  (case button
   ((up)
    (cond
     ((current-menu)
      (menu-scroll! (current-menu) 'up))
     (else
      (move-player-and-check-complete! global-game-state 'up))))
   ((down)
    (cond
     ((current-menu)
      (menu-scroll! (current-menu) 'down))
     (else
      (move-player-and-check-complete! global-game-state 'down))))
   ((left)
    (cond
     ((current-menu)
      (display "Pressed left in a menu.\n"))
     (else
      (move-player-and-check-complete! global-game-state 'left))))
   ((right)
    (cond
     ((current-menu)
      (display "Pressed right in a menu.\n"))
     (else
      (move-player-and-check-complete! global-game-state 'right))))
   ((a)
    (cond
     ((current-menu)
      (menu-select! (current-menu)))
     (else
      (display "Pressed a outside a menu.\n"))))
   ((b)
    (cond
     ((current-menu)
      (menu-close! (current-menu)))
     (else
      (try-undo-last-move! global-game-state))))
   ((x)
    (cond
     ((current-menu)
      (display "Pressed x in a menu.\n"))
     (else
      (open-pause-menu! global-game-state))))
   ((y)
    (cond
     ((current-menu)
      (display "Pressed y in a menu.\n"))
     (else
      (display "Pressed y outside a menu.\n"))))
   (else (error "button not recognized" button)))
  "Accepted")

